package com.liqi.frame.comm.token;

import com.liqi.frame.comm.po.User;
import com.liqi.frame.comm.util.ShiroUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by liqi on 2017/12/19.
 * liqiwork@qq.com
 */
public class AuthUtil {
    public static void setMockUser(User user) {
        String[] resource = new String[]{"spring-shiro.xml"};
        ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext(resource);
        org.apache.shiro.mgt.SecurityManager securityManager = (org.apache.shiro.mgt.SecurityManager)appCtx.getBean("securityManager");
        SecurityUtils.setSecurityManager(securityManager);

        UserToken token = new UserToken(user.getUsername(), user.getPswd());
        ShiroUtil.getSubject().login(token);
    }
}
